package com.yulongtian.oneProblemEveryDay.month202212;

import java.util.Arrays;
import java.util.Comparator;
import java.util.HashSet;
import java.util.Set;

/**
 * https://leetcode.cn/problems/second-largest-digit-in-a-string/
 *
 * @author yulongTian
 * @create 2022-12-13 11:06
 */
public class Test08 {
    public static void main(String[] args) {

    }

    public int secondHighest(String s) {
        Set<Integer> mySet = new HashSet<>();
        for (int i = 0; i < s.length(); i++) {
            char c = s.charAt(i);
            if (c >= '0' && c <= '9') {
                mySet.add(c - '0');
            }
        }

        int[] arr = new int[mySet.size()];
        int index = 0;
        for (Integer integer : mySet) {
            arr[index++] = integer;
        }

        Arrays.sort(arr);

        if(index>=2){
            return arr[index-2];
        }else{
            return -1;
        }


    }

}
